//
//  WXMessage.swift
//  SwiftIM
//
//  Created by WuZhijian on 14/12/6.
//  Copyright (c) 2014年 com.liveln. im. All rights reserved.
//

import Foundation

//消息结构
struct WXMessage {
    var body:String = ""
    var from:String = ""
    var isComposing:Bool = false
    var isDelay:Bool = false
    var isMe:Bool = false
}

//状态结构
struct status {
    var name:String = ""
    var isOnLine:Bool = false
}

//从数组中删除指定值的正确索引
func removeValueFromArray(value:String, inout aArray:[WXMessage])
{
    var correctArr  =  [Int]()
    correctArr = getRemoveIndex(value,aArray)
    
    //从原数组中删除指定值
    for index in correctArr
    {
        aArray.removeAtIndex(index)
    }
    
}

//获取正确的删除索引
func getRemoveIndex(value:String, aArray:[WXMessage]) -> [Int]
{
    var indexArr = [Int]()
    var correctArr  =  [Int]()
    
    //获取指定值数组中的索引
    for (index,_) in enumerate(aArray)
    {
        if (value == aArray[index].from)
        {
            indexArr.append(index)
        }
    }
    
    //计算正确的删除索引
    for (index, originIndex) in enumerate(indexArr)
    {
        //正确的索引
        var y = 0
        
        //用指定值在原数组中的索引，减去索引数组中的索引
        y = originIndex - index
        
        //插入到正确的索引数组中
        correctArr.append(y)
    }
    
    //返回正确的索引
    return correctArr
    
}